{% extends 'base.html' %}

{% block title %}个人中心 - 电影推荐系统{% endblock %}

{% block content %}
<div class="container py-5">
    <div class="row">
        <div class="col-lg-4">
            <div class="card mb-4">
                <div class="card-body text-center">
                    <img src="https://ui-avatars.com/api/?name={{ user.username }}&background=random&size=128" alt="头像" 
                         class="rounded-circle img-fluid" style="width: 150px;">
                    <h5 class="my-3">{{ user.username }}</h5>
                    <p class="text-muted mb-1">电影爱好者</p>
                    <p class="text-muted mb-4">加入时间: {{ user.date_joined|date:"Y-m-d" }}</p>
                </div>
            </div>
            <div class="card mb-4">
                <div class="card-body">
                    <div class="row">
                        <div class="col-sm-4">
                            <p class="mb-0 fw-bold">总评分</p>
                        </div>
                        <div class="col-sm-8">
                            <p class="text-muted mb-0">{{ ratings_count }}</p>
                        </div>
                    </div>
                    <hr>
                    <div class="row">
                        <div class="col-sm-4">
                            <p class="mb-0 fw-bold">平均评分</p>
                        </div>
                        <div class="col-sm-8">
                            <p class="text-muted mb-0">{{ average_rating|floatformat:1 }}</p>
                        </div>
                    </div>
                    <hr>
                    <div class="row">
                        <div class="col-sm-4">
                            <p class="mb-0 fw-bold">最常评价</p>
                        </div>
                        <div class="col-sm-8">
                            <p class="text-muted mb-0">{{ favorite_genre }}</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-lg-8">
            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">最近评分</h5>
                    <a href="{% url 'user_ratings' %}" class="btn btn-sm btn-outline-primary">查看全部</a>
                </div>
                <div class="card-body">
                    {% if recent_ratings %}
                    <div class="list-group">
                        {% for rating in recent_ratings %}
                        <div class="list-group-item list-group-item-action">
                            <div class="d-flex w-100 justify-content-between">
                                <h5 class="mb-1">{{ rating.movie.title }}</h5>
                                <div class="rating-stars">
                                    {% for i in "12345" %}
                                    <span class="star {% if forloop.counter <= rating.rating %}filled{% endif %}">★</span>
                                    {% endfor %}
                                </div>
                            </div>
                            <p class="mb-1">{% if rating.comment %}{{ rating.comment }}{% else %}暂无评论{% endif %}</p>
                            <small class="text-muted">{{ rating.created_at|date:"Y-m-d H:i" }}</small>
                        </div>
                        {% endfor %}
                    </div>
                    {% else %}
                    <div class="alert alert-info">
                        您还没有对任何电影进行评分。
                        <a href="{% url 'movie_list' %}" class="alert-link">浏览电影</a>并开始评分吧！
                    </div>
                    {% endif %}
                </div>
            </div>
            
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">个性化推荐</h5>
                    <a href="{% url 'user_recommendations' %}" class="btn btn-sm btn-outline-primary">查看全部</a>
                </div>
                <div class="card-body">
                    {% if recommendations %}
                    <div class="row">
                        {% for movie in recommendations %}
                        <div class="col-md-4 mb-3">
                            <div class="card h-100">
                                <img src="{{ movie.poster_url|default:'https://via.placeholder.com/150x225?text=暂无海报' }}" 
                                     class="card-img-top" alt="{{ movie.title }}">
                                <div class="card-body p-2">
                                    <h6 class="card-title text-truncate">{{ movie.title }}</h6>
                                    <p class="card-text small mb-1">{{ movie.year }}</p>
                                    <a href="{% url 'movie_detail' movie.id %}" class="btn btn-sm btn-outline-primary w-100">查看</a>
                                </div>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                    {% else %}
                    <div class="alert alert-info">
                        开始评分以获取个性化推荐！
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 